/*****************************************************************************/
/**
 *  @file   main.cpp
 *  @author Naohisa Sakamoto
 */
/*----------------------------------------------------------------------------
 *
 *  Copyright (c) Visualization Laboratory, Kyoto University.
 *  All rights reserved.
 *  See http://www.viz.media.kyoto-u.ac.jp/kvs/copyright/ for details.
 *
 *  $Id$
 */
/*****************************************************************************/
#include <iostream>
#include <kvs/glut/Application>
#include <kvs/CommandLine>
#include "MainView.h"
#include "OverView.h"
#include "DataSet.h"
#include "ResourceMonitor.h"


int main( int argc, char** argv )
{
    // Command line parser.
    kvs::CommandLine arg( argc, argv );
    arg.addHelpOption();
    arg.addValue( "Directory name for volume data (*.fld)" );
    arg.addValue( "Directory name for particle data (*.kvsml)" );
    if ( !arg.parse() ) return 1;

    // Read argument values.
    std::string volume_dirname = arg.value<std::string>(0);
    std::string particle_dirname = arg.value<std::string>(1);

    // Data set.
    DataSet data_set;
    if ( !data_set.load( volume_dirname, particle_dirname ) )
    {
        kvsMessageError( "Cannot load the volume and particle files." );
        return 1;
    }

    // Viewers.
    kvs::glut::Application app( argc, argv );
    MainView main_view( &app );
    OverView over_view( &app );

    main_view.attachOverViewScreen( &over_view );
    main_view.attachDataSet( &data_set );
    over_view.attachDataSet( &data_set );

    // Layout.
    size_t x = main_view.x();
    size_t y = main_view.y();
    size_t w = main_view.width();
    over_view.setPosition( x + w + 10, y );

    // Resource monitor.
    ResourceMonitor resource_monitor;
    main_view.attachResourceMonitor( &resource_monitor );
    over_view.attachResourceMonitor( &resource_monitor );

    // Load initial object.
    main_view.loadObject();
    over_view.loadObject();

    // Run app.
    main_view.show();
    over_view.show();
    return app.run();
}
